#ifndef MAINWIDGET_H
#define MAINWIDGET_H

#include <QWidget>
//#include <QtNetwork>
#include <QTcpSocket>
#include <QUdpSocket>
#include "appjson.h"
#include <QStandardItemModel>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWidget; }
QT_END_NAMESPACE

class WidgetLogin; // 前向声明


class MainWidget : public QWidget
{
    Q_OBJECT

public:
    MainWidget(QWidget *parent = nullptr);
    ~MainWidget();

    void setDialog(WidgetLogin *dlg1);
private:
    Ui::MainWidget *ui;
    void initForm();
    void initConfig();

    QTcpSocket* m_TcpSocket;
    QUdpSocket* m_UdpSocket;

    void TcpConnected();
    void TcpDisconnected();
    void TcpReadyRead();
    void TcpDisplayError(QAbstractSocket::SocketError socketError);

    void UdpReadyRead();
    void UdpDisplayError(QAbstractSocket::SocketError socketError);

    AppJson* m_AppJson = NULL;
    QJsonDocument m_jsonDoc;

    QStandardItemModel* m_modelData = NULL;

    void SaveData();

    bool m_Comm = false;
    //设置连接界面
    void setCommEnabled(bool bComm);

    WidgetLogin *dialogLogin;

    void unConnect();

private slots:
    void onButtonRunClicked();
    void onButtomNewClicked();
    void onButtomUpdateClicked();
    void onButtomDelClicked();
    void onButtomLinkClicked();

    void onButtonRtLoginClicked();
};
#endif // MAINWIDGET_H
